import { createRouter, createWebHistory } from 'vue-router';
import login from '@/views/login/index.vue';
import layout from '@/layout/index.vue';
const files = import.meta.globEager('../views/**/*.vue');
let modules = {};
for (const key in files) {
  if (key.indexOf('login') < 0) modules[files[key].default.name] = files[key].default;
}
// const children = [];
// for (const key in files) {
//   var route = {
//     path: '/',
//     name: files[key].default.name,
//     component: files[key].default,
//     meta: {
//       keepAlive: true,
//     },
//   };
//   children.push(route);
// }
const routes = [
  {
    path: '/',
    name: 'layout',
    component: layout,
    meta: {
      keepAlive: true,
    },
    //children: children,
    children: [
      {
        path: '/',
        name: 'module',
        components: { ...modules },
        meta: {
          keepAlive: true,
        },
      },
    ],
    // children: [
    //   {
    //     path: '',
    //     name: 'module1',
    //     components: { module1: module },
    //     meta: {
    //       keepAlive: true,
    //     },
    //   },
    // ],
    // children: [
    //   {
    //     path: '/',
    //     name: 'module',
    //     component: module,
    //     meta: {
    //       keepAlive: true,
    //     },
    //   },
    //   {
    //     path: '/',
    //     name: 'employee',
    //     component: employee,
    //     meta: {
    //       keepAlive: true,
    //     },
    //   },
    // ],
  },
  {
    path: '/login',
    name: 'login',
    component: login,
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});
export default router;
